import {
    fetchDeviceInfo
} from '@/services/device';
import {
    getParams
} from '@/utils/util';
const labelMappings = {
    'product_type': '设备型号',
    'device_iccid': 'ICCID',
    'ota_process': 'OTA升级进度',
    'com_version': '通信板固件版本',
    'radar_version': '雷达固件版本',
    'firmware_version': '固件版本',
    'backplane_version': '底板版本'
}
const comversionMappings = {
    '0': '空闲',
    '1': '升级中',
    '2': '升级完成'
}
const app = getApp();
Page({
    data: {
        staticPrefix: app.globalData.STATIC_PREFIX,
    },
    async onLoad(options) {
        const { device_imei } = getParams(options.params);
        const res = await fetchDeviceInfo({ device_imei });
        console.log(res)
        let obj = {
            product_type: res.data['product_type'],
            device_iccid: res.data['device_iccid']
        }
        if(res.data.device_type == '2') {
            if(res.data.product_type == 'DX1') {
                obj['ota_process'] = comversionMappings[res.data['ota_process']];
                obj['com_version'] = res.data['com_version'];
                obj['radar_version'] = res.data['radar_version'];
            }
            if(res.data.product_type == 'DD_T') {
                obj['com_version'] = res.data['com_version'];
                obj['radar_version'] = res.data['radar_version'];
            }
        }
        if(res.data.device_type == '13') {
            obj['firmware_version'] = res.data['firmware_version'];
        }
        if(res.data.device_type == '14') {
            obj['firmware_version'] = res.data['firmware_version'];
            obj['backplane_version'] = res.data['backplane_version'];
        }
        let result = [];
        for (let [key, value] of Object.entries(obj)) {
            result.push({
                key: labelMappings[key],
                value
            })
        }
        this.setData({
            ...res.data,
            result
        })
    }
})